#define _CRT_SECURE_NO_WARNINGS 1

#include <vector>
using namespace std;

class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int minprice = INT_MAX;
        int maxProfit = 0;
        for (auto e : prices)
        {
            maxProfit = max(maxProfit, e - minprice);
            minprice = min(minprice, e);
        }
        return maxProfit;
    }
};